#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QLabel>
#include<QDebug>
#include<QKeyEvent>
#include"mylabel.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->label->installEventFilter(this);


}

MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::keyPressEvent(QKeyEvent*ev)
{
    if(ev->key()==Qt::Key_A)
    {
        qDebug()<<"A被按下";
    }
}
 bool  MainWindow::eventFilter(QObject *watched, QEvent *event)
 {
     if (event->type() == QEvent::Enter) {

                 if (watched == ui->label) {
                     qDebug() << "按钮1被点击";
                     return true;
                }

             return false; // 允许事件继续传递
         }

 }

